home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 November / Chip_1999-11_cd.bin / zkuste / MacOS / DATA / FILES / POWER64.HQX / Power64 2.5.1 / Power64 2.5.1 - Read Me.rsrc / TEXT_140.txt < prev    next >
Text File  |  1999-09-20  |  27KB  |  488 lines

  1. Appendix C : Emulator File Formats
  2.  
  3. This section describes all the common file formats in the field of Commodore 64 emulation. It is intended for the interested programmer, who might wish to learn the internal workings of the emulator. If you are only interested in playing your favorite C64 game, then you do not need to worry about these details.
  4.  
  5.  
  6. C.1 *.P00 Program Format
  7.  
  8. The *.P00 format is a flexible file format, that is able to support all common types of C64 files. As it has a magic constant at the head of the file it also enables the emulator to make sure that no invalid files are used. This makes it the recommended file format for single files.
  9.  
  10. typedef struct
  11.  {
  12.   Byte P00Magic[8];    /* $00 - $07 */
  13.   Byte OrigFName[17];  /* $08 - $18 */
  14.   Byte RecordSize;     /* $19 */
  15.   Byte Data[n];        /* $1A - ... */
  16.  } P00File;
  17.  
  18. P00Magic   - Magic constant 'C64File' =
  19.                               {$43, $36, $34, $46, $69, $6C, $65, $00}
  20. OrigFName  - Original C64 filename (CBM Charset)
  21. RecordSize - Record size for RELative files
  22. Data       - The actual data
  23.  
  24. This file format was first used by Wolfgang Lorenz in PC64. Note that the extension *.P00 is not fix. rather the 'P' stands for 'PRG' and can become an 'S' for 'SEQ', or 'R' for 'REL'. Furthermore the '00' can be used count to '01','02','03'... to resolve name conflicts caused by truncation a 16 character C64 filename to a 8+3 MS-DOS name. Of course this is not relevant on a Macintosh, it's just a hint if you should ever happen to run across a *.P01 file.
  25.  
  26.  
  27. C.2 *.C64 Program Format
  28.  
  29. The *.C64 format is the exact format that the original Commodore 64 uses to store a programs to either disk or tape.
  30.  
  31. typedef struct
  32.  {
  33.   Byte LoadAddrLow, LoadAddrHigh; /* $00 - $01 */
  34.   Byte PrgData[n];                /* $02 - ... */
  35.  } C64File;
  36.  
  37. LoadAddr - The address in C64 RAM at which the program will get stored when loaded with secondary device number 1.
  38. PrgData - The actual program.
  39.  
  40. This file format was introduced to the world of emulators by Miha Peternel in C64S. As can be seen from the above description this is a rather simple file format. Still it's use is not recommended as it does not provide the emulator with any possibility to make sure that only valid files are used.
  41.  
  42.  
  43. C.3 *.X64 Floppy Disk Image Format 
  44.  
  45. The *.X64 format is flexible format for disk image files that supports a wide range of floppy disks. Note so, that the implementation of *.X64 in Power64 can only handle 1541 disks.
  46.  
  47. typedef struct
  48.  {
  49.   Byte X64Magic[4];   /* $00 - $03 */
  50.   Byte Version[2];    /* $04 - $05 */
  51.   Byte DiskType;      /* $06 */
  52.   Byte TrackCnt;      /* $07 */
  53.   Byte SecondSide;    /* $08 */
  54.   Byte ErrorFlag;     /* $09 */
  55.   Byte Reserved[22];  /* $0A - $1F */
  56.   Byte DiskInfo[31];  /* $20 - $3E */
  57.   Byte ConstZero;     /* $3F */
  58.   Byte DiskImage[683 * 256];
  59.  } X64File;
  60.  
  61. X64Magic   - Magic constant 'C'1541/64 = {$43, $15, $41, $64}
  62. Version    - C1541 Version 2.6 = {$02, $06}
  63. DiskType   - Floppy disk type: 1541 = {$01}
  64.              Other defined values: (not usable for Power64)
  65.                0..1540, 1..1541, 2..1542, 3..1551,
  66.         4..1570, 5..1571, 6..1572, 8..1581,
  67.        16..2031&4031, 17..2040&3040, 18..2041
  68.        24..4040,
  69.        32..8050, 33..8060, 34..8061,
  70.        48..SFD 1001, 49..8250, 50..8280,
  71. TrackCnt   - Number of Tracks on the Disk (Side 0) = {35}
  72. SecondSide - Is it a Double Sided Disks (0..No, 1..Yes) = {$00}
  73. ErrorFlag  - Flag for Error (precise meaning unclear) (unused)
  74. Reserved   - Must be $00
  75. DiskInfo   - Description of the Disk Image (in ASCII or ISO Latin/1)
  76. ConstZero  - Must be $00
  77. DiskImage  - 683 disk sectors of 256 bytes each.
  78.              (For more information on DiskImage see also: *.D64)
  79.  
  80. The *.X64 disk image format was originally created by Teemu Rantanen for use in X64.
  81. As *.X64 uses a well defined header the emulator is able to make sure that only valid files are used. This is a clear advantage over the (unfortunately more widespread) *.D64 format.
  82.  
  83.  
  84. C.4 *.D64 Floppy Disk Image Format 
  85.  
  86. The *.D64 file format is a 1:1 copy of all sectors as they appear on a floppy disk. On a C1541 formatted disk (and thus also in a *.D64 file) each sector consists of 256 Byte. In order to be able to deal with bad sectors the *.D64 format optionally features an additional error byte per sector. A disk that was formatted by using the standard C1541 command NEW will have 35 tracks containing a total of 683 sectors. With the use of special software it is possible to format and write disks with up to 40 tracks. While the extra tracks are not within the original specification such disks are readable with most C1541 drives (Note: Reading does not require special software.).
  87.  
  88. Currently there are four different types of *.D64 formats:
  89. ΓÇó 683 Sectors (= 35 Tracks) without error info
  90.    (Total Size: 174848 Byte = 170.75 KByte)
  91. ΓÇó 683 Sectors (= 35 Tracks) with error info
  92.    (Total Size: 175531 Byte = 171.42 KByte)
  93. ΓÇó 768 Sectors (= 40 Tracks) without error info
  94.    (Total Size: 196608 Byte = 192 KByte)
  95. ΓÇó 768 Sectors (= 40 Tracks) with error info
  96.    (Total Size: 197376 Byte = 192.75 KByte)
  97.  
  98. Note that tracks at the outside edge of the disk contain more sectors than those near to the disks center (Zone Bit Recording). The number of sectors on each track is:
  99.       Tracks   1..17 - 21 Sectors
  100.       Tracks 18..24 - 19 Sectors
  101.       Tracks 25..30 - 18 Sectors
  102.       Tracks 31..35 - 17 Sectors
  103.       Tracks 36..40 - 17 Sectors (non standard!)
  104.  
  105. The Block Allocation Map (BAM) is stored on track 18 - sector 0; the directory starts at track 18 - sector 1.
  106.  
  107. For storage in a *.D64 image the sectors are arranged in the followingway:
  108.   Track  1 - Sector  0: Offset   0 * 256
  109.   Track  1 - Sector  1: Offset   1 * 256
  110.                 .....
  111.   Track  1 - Sector 20: Offset  20 * 256
  112.   Track  2 - Sector  0: Offset  21 * 256
  113.   Track  2 - Sector  1: Offset  22 * 256
  114.                 .....
  115.   Track  2 - Sector 20: Offset  41 * 256
  116.   Track  3 - Sector  0: Offset  42 * 256
  117.                 .....
  118.   Track 18 - Sector  0: Offset 357 * 256
  119.   Track 18 - Sector  1: Offset 358 * 256
  120.                 .....
  121.   Track 35 - Sector  0: Offset 666 * 256
  122.   Track 35 - Sector  1: Offset 667 * 256
  123.                 .....
  124.   Track 35 - Sector 16: Offset 682 * 256
  125.  
  126. Note that tracks are counted starting with track 1, while sector numbers start with 0.
  127.  
  128. typedef struct
  129.  {
  130.   Byte DiskImage[SectorCnt][256];
  131.   Byte ErrorInfo[SectorCnt]; /* Optional */
  132.  } D64File;
  133.  
  134. DiskImage - 256 Bytes per Sector
  135. ErrorInfo - 1 Byte per Sector
  136. Note that the error information for all sectors is concentrated  at the end of the file. There is no interweaving of disk image data and error information on a per sector basis.
  137. The meaning of the ErrorInfo is given in the following table:
  138.  
  139.        Code  Error  Type   1541 error description
  140.     ----  -----  ----   ------------------------------
  141.      01    00    N/A    No error, sector ok.
  142.      02    20    Read   Header block not found
  143.      03    21    Seek   No sync character
  144.      04    22    Read   Data block not present
  145.      05    23    Read   Checksum error in data block
  146.      06    24    Write  Write verify (on format)
  147.      07    25    Write  Write verify error
  148.      08    26    Write  Write protect on
  149.      09    27    Seek   Checksum error in header block
  150.      0A    28    Write  Write error
  151.      0B    29    Seek   Disk ID mismatch
  152.      0F    74    Read   Disk Not Ready (no device 1)
  153.  
  154.  
  155. C.5 ZipCode File Format (1!*, 2!*, etc.)
  156.  
  157. This is a compressed version of a D64 file that is frequently found on C64 sites that have already been around for a long time (and have served C64 owners before emulation became common). A single D64 file is split into 4 (35 tracks) or 5 (40 tracks) segments. Each part is then packed using the simple (and poorly compressing) Run Length Encoding compression method.
  158.  
  159. The primary reason for the existance of this file format is that every segment of such a ZipCode File is less than 44 KByte in size, and can thus easily be handled by a real C64 and its 1541 disk drive (say after a transmittion via modem from a BBS). Furthermore packing and unpacking are very fast on a C64.
  160.  
  161. Modern computers, like a Power Macintosh, that are used to run C64 emulators have no problem handling files 171KByte in size (like D64 files), so they do not benefit from splitting one 'large' file in several smaller. In fact, due to the large allocations units of modern hard disks and CD-ROMs the space wasted by 4 half filled last blocks of the 4 files is likely to exceeds the savings from compression for reasonable well filled floppy disks. Furthermore modern compression formats like Zip, GZ, LHA or SIT offer much besser compression that the RLE used in the ZipCode. 
  162.  
  163. While ZipCode is not the best choice of a file format for an emulator it is still a good format on a real C64 and many sites offer their files in ZipCode format to support the faithful C64-addicts that stick to the real hardware.
  164.  
  165. Note that there are also two other Zip formats for the C64, that are not supported by Power64. They use the filename-prefixes 1!!, 2!!, 3!!ΓǪ  and A!, B!, C!ΓǪ  respectively. They are described in the File Format collection of Peter Schepers the author of 64COPY (schepers@dcs1.uwaterloo.ca), but I have never seen files in either format anywhere on the web.
  166.  
  167. The contents of the floppy disk is devided onto the 4 or 5 segments accoring to the following table:
  168.    FileName  Track Range  Block Count
  169.    --------  -----------  -----------
  170.    1!xxxxxx     1 - 8     168 Sectors
  171.    2!xxxxxx     9 - 16    168 Sectors
  172.    3!xxxxxx    17 - 25    172 Sectors
  173.    4!xxxxxx    26 - 35    175 Sectors
  174.    5!xxxxxx    36 - 40     85 Sectors (only for 40 track disk images)
  175.  
  176. All segments have a similar structure based on compressed disk sectors. Note that the first segments header is slightly different from the rest.
  177.  
  178. typedef struct
  179.  {
  180.   Byte LoadAddr[2];     /* Const. $03FE = { 0xFE, 0x03}; */
  181.   Byte FloppyID[2];
  182.   ZipSector Image[168];
  183.  } ZipSegment_1!;
  184.  
  185. typedef struct
  186.  {
  187.   Byte LoadAddr[2];     /* Const. $0400 = { 0x00, 0x04}; */
  188.   ZipSector Image[...];
  189.  } ZipSegment_n!;       /* n = {2, 3, 4, 5} */
  190.  
  191. Compression takes place on a sector per sector basis. For each sector there is the following structure:
  192.  
  193. typedef struct
  194.  {
  195.   Byte Track;     /* Track Number and Compression Mode */
  196.   Byte Sector;    /* Sector Number */
  197.   union {
  198.     { Byte NoCompression[256]; } Mode00;
  199.     { Byte SingleByte; } Mode01;
  200.     { Byte Length;
  201.       Byte RepeatChar;
  202.       Byte RLEData[Length]; } Mode10;
  203.    } Data;
  204.  } ZipSector;
  205.  
  206. Track gives the track number of the compressed sector in Bit 5 to Bit 0. Bits 7&6 give the compression mode.
  207. Sector gives the sector number of the compressed sector.
  208. The meaning of Data depends on the compression mode:
  209.  
  210. Compression Modes:
  211. 00 - No compression; The sector is stored in full. The 256 Data Bytes give the sectors contents.
  212. 01 - The entire sector is filled with a single Byte. A single Data Byte will be repeated 256 times to fill the sector.
  213. 10 - Run Length Encoded Sector - Length gives the number of Bytes of compressed RLEData. RepeatChar is a Byte that does not appear in the original sector and that is now used as a marker for runlength encoded pieces of data. RLEData  different from RepeatChar is just plain, uncompressed data, that can be directly copied. After RepeatChar is encountered, the next Byte of RLEData gives the Length of the Run and 
  214. a third Byte denotes the Byte to be repeated.
  215. 11 -Unused   
  216.  
  217. The sectors of a track are NOT stored in a linear fashion (1, 2, 3, 4ΓǪ). To make packing and unpacking much faster on a real 1541 interleaving is used. The proper sequence of sectors depends on the number of sectors in a track and can be seen below.
  218. Track  1-17:   0  11  1  12  2  13  3  14  4  15  5  16  6  17  7  18  8  19  9  20  10
  219. Track 18-24:  0  10  1  11  2  12  3  13  4  14  5  15  6  16  7  17  8  18  9
  220. Track 25-30:  0    9  1  10  2  11  3  12  4  13  5  14  6  15  7  16  8  17
  221. Track 31-40:  0    9  1  10  2  11  3  12  4  13  5  14  6  15  7  16  8
  222.  
  223. Example for the first few sectors of the first segment (1!*):
  224. $0000: 0xFE, 0x03,       /* Load Addr. Const $03FE */
  225. $0002: 0x36, 0x34,       /* Floppy ID */
  226. $0004: 0x41, 0x00, 0x00, /* Track 1, Sector  0 filled with 0x00 */
  227. $0007: 0x41, 0x0B, 0x00, /* Track 1, Sector 11 filled with 0x00 */
  228. $000B: 0x41, 0x01, 0x00, /* Track 1, Sector  1 filled with 0x00 */
  229. $0007: 0x01, 0x0C,       /* Track 1, Sector 12 uncompressed Data */
  230. ... 256 Byte Data ...
  231. $0109: 0x81, 0x02,       /* Track 1 ,Sector 2 RLE Encoded */
  232.        0x12, 0xEA,       /* 0x12(18) Byte, RepeatChar: 0xEA */
  233.        0x45, 0x22, 0x34, 0x08,/* Plain Data */
  234.        0xEA, 0xD0, 0x77,      /* 0x77 repeated 0xD0 times */
  235.        0x12, 0xFF, 0x00, 0x00, 0x32, 0x11 /* Plain Data */
  236.        0xEA, 0x24, 0x55,      /* 0x55 repeated 0x24 times */
  237.        0xEE, 0x98,            /* Plain Data */
  238. $011F: 0x41, 0x0D, 0x11  /* Track 1, Sector 13 filled with 0x11 */
  239. $0122: ...
  240.  
  241.  
  242. C.6 *.Lynx File Format 
  243.  
  244. The Lynx (or LNX or Ultimate Lynx) file format was developed by Will Corley for use on the C64(!). It is designed around blocks of 254 Bytes.This corresponds to the 256 Bytes of a 1541 disk sector minus the 2 Bytes that contain the next track/sector information and makes it easy to copy files between 1541 disks and Lynx files.
  245. Unfortunately the Lynx header is written in a format that is somewhat harder to handle than that of a T64 or D64 file, and thus the format has received little attention by emulator  authors.
  246.  
  247. typedef struct
  248.  {
  249.   Byte Directory[DirSectorCnt * 254];
  250.   Byte Data[DataSectorCnt * 254];
  251.  } LynxFile;
  252.  
  253. The Directory starts out with a small BASIC program which, when loaded and run, displays the message "Use LYNX to dissolve this file". The  actual message and size of the program can change. Usually, its 94 bytes long, from $0000 to $005D. Note that some emulators depend on the exact size of 94 Bytes and also require that the text 'LYNX' can be found at offset $003C to $003F. 
  254.  
  255. $0000: 0x01, 0x08, 0x5B, 0x08, 0x0A, 0x00, 0x97, 0x35, /* .......5 */
  256. $0008: 0x33, 0x32, 0x38, 0x30, 0x2C, 0x30, 0x3A, 0x97, /* 3280,0:. */
  257. $0010: 0x35, 0x33, 0x32, 0x38, 0x31, 0x2C, 0x30, 0x3A, /* 53281,0: */
  258. $0018: 0x97, 0x36, 0x34, 0x36, 0x2C, 0xC2, 0x28, 0x31, /* .646,.(1 */
  259. $0020: 0x36, 0x32, 0x29, 0x3A, 0x99, 0x22, 0x93, 0x11, /* 62):.".. */
  260. $0028: 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x22, /* ......." */
  261. $0030: 0x3A, 0x99, 0x22, 0x20, 0x20, 0x20, 0x20, 0x20, /* :."      */
  262. $0038: 0x55, 0x53, 0x45, 0x20, 0x4C, 0x59, 0x4E, 0x58, /* USE LYNX */
  263. $0040: 0x20, 0x54, 0x4F, 0x20, 0x44, 0x49, 0x53, 0x53, /*  TO DISS */
  264. $0048: 0x4F, 0x4C, 0x56, 0x45, 0x20, 0x54, 0x48, 0x49, /* OLVE THI */
  265. $0050: 0x53, 0x20, 0x46, 0x49, 0x4C, 0x45, 0x22, 0x3A, /* S FILE": */
  266. $0058: 0x89, 0x31, 0x30, 0x00, 0x00, 0x00,             /* .10...   */
  267.  
  268. This is equivalent to the following BASIC program: 
  269.    10 POKE53280,0:POKE53281,0:POKE646,PEEK(162):
  270.         PRINT"<CLS><DOWN><DOWN><DOWN><DOWN><DOWN><DOWN><DOWN><DOWN>":
  271.         PRINT"     USE LYNX TO DISSOLVE THIS FILE":
  272.         GOTO10
  273.  
  274. Following this is a <CR> and the number of blocks of the directory in ASCII with spaces on both sides. For a directory with just 1 block that would be:
  275. $005E:  0x0D, 0x20, 0x31, 0x20, 0x20                    /* . 1     */
  276.  
  277. After this there is the "signature" of the archive, an CBM lower case (ASCII for the most part) text ending in <CR> that describes the Lynx archive. Normally this signature will contain the string 'LYNX'.
  278. Power64 uses:
  279. $0063: 0x2A, 0x4C, 0x59, 0x4E, 0x58, 0x20, 0x41, 0x52, /* *LYNX AR */
  280. $006B: 0x43, 0x48, 0x49, 0x56, 0x45, 0x20, 0x42, 0x59, /* CHIVE BY */
  281. $0073: 0x20, 0x50, 0x4F, 0x57, 0x45, 0x52, 0x36, 0x34  /*  POWER64 */
  282. $007B: 0x0D
  283.  
  284. This is followed by the number of files in the Lynx archive, as before this is given as a ASCII number surrounded by spaces and delimited by <CR>.
  285. For a directory with 3 files that would be:
  286. $007C: 0x20, 0x33, 0x20, 0x0D                          /*  3 .     */
  287.  
  288. Following these headers is the actual directory. Each file is described by its filename (in PETASCII, often padded to 16 characters by shifted-spaces), followed by the size of the file (plus 2 bytes for the address) in blocks of 254 bytes, the file type (P, S, R, U), the size in bytes of the last block. If the file type is Relative, this entry is the Record size, and the next entry is the last block size. If the file type is not Relative, the next entry will be the next filename. Relative files are not supported by Power64. Every entry is terminated by a <CR>, numbers are surrounded by spaces. For example this could be:
  289.  
  290. File 1: "Block Out", PRG, 2+2519 Byte (2521 = (10-1) * 254 + 235)
  291. $0080: 0x42, 0x4C, 0x4F, 0x43, 0x4B, 0x20, 0x4F, 0x55, /* BLOCK OU */
  292. $0088: 0x54, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, /* TΓÇáΓÇáΓÇáΓÇáΓÇáΓÇáΓÇá */
  293. $0090: 0x0D, 0x20, 0x31, 0x30, 0x20, 0x0D, 0x50, 0x0D, /* . 10 .P. */
  294. $0098: 0x20, 0x32, 0x33, 0x35, 0x20, 0x0D,             /*  235 .   */
  295.  
  296. File 2: "Serpentine", PRG, 2+8703 Byte (8705 = (35-1) * 254 + 69)
  297. $009E: 0x53, 0x45, 0x42, 0x4C, 0x45, 0x4E, 0x54, 0x49, /* SERPENTI */
  298. $00A6: 0x4E, 0x45, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, /* NEΓÇáΓÇáΓÇáΓÇáΓÇáΓÇá */
  299. $00AE: 0x0D, 0x20, 0x33, 0x35, 0x20, 0x0D, 0x50, 0x0D, /* . 35 .P. */
  300. $00B6: 0x20, 0x36, 0x39, 0x20, 0x0D,                   /*  69 .    */
  301.  
  302. File 3: "Quadromania", PRG, 2+7056 Byte (7058 = (28-1) * 254 + 200)
  303. $00BB: 0x51, 0x55, 0x41, 0x44, 0x52, 0x4F, 0x4D, 0x41, /* QUADROMA */
  304. $00C3: 0x4E, 0x49, 0x41, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, /* NIAΓÇáΓÇáΓÇáΓÇáΓÇá */
  305. $00CB: 0x0D, 0x20, 0x32, 0x38, 0x20, 0x0D, 0x50, 0x0D, /* . 28 .P. */
  306. $00D3: 0x20, 0x32, 0x30, 0x30, 0x20, 0x0D,             /*  200 .   */
  307.  
  308. The actual files follow the directory. Each file consists of 2 bytes load address plus the actual data.
  309.  
  310. Note that the directory and every files size is a multiple of 254 bytes. If the actual information requires less space, then there is a wasted gap, that is filled with 0x00 in Power64 (other implementations vary).
  311.  
  312. In the above example the directory consists of just one block, and thus Block Out starts at offset 1 * 254. The second file (Serpentine) starts at offset (1+10) * 254 and Quadromania begins at (1+10+35) * 254.
  313.  
  314. $00FE: 0x01, 0x08, 0x26, 0x08, 0xC1, 0x07, 0x9E, 0x32, /* ..&.i..2 */
  315. $0106: 0x30, 0x38, 0x38, 0x3A, 0x12, 0x42, 0x4C, 0x4F, /* 088:.BLO */
  316. $011E: 0x43, 0x4B, 0xAB, 0x4F, 0x55, 0x54, ...         /* CK-OUT.. */
  317. ... /* (1+10) * 254 = $0AEA */
  318. $0AEA: 0x01, 0x08, 0x26, 0x08, 0xC1, 0x07, 0x9E, 0x32, /* ..&.┬í..2 */
  319. $0AF2: 0x30, 0x38, 0x38, 0x3A, 0x12, 0x53, 0x45, 0x52, /* 088:.SER */ 
  320. $0AFA: 0x50, 0x45, 0x4E, 0x54, 0x49, 0x4E, 0x45,...    /* PENTINE  */
  321. ...
  322.  
  323.  
  324. C.7 *.T64 Tape Image Format 
  325.  
  326. The *.T64 file format is a very well designed (so in former times poorly documented) format, developed by Miha Peternel for C64S. Like a disk image file it is able to contain many logical files; a great help when keeping lots of files organized. On the other hand there is very little organizational overhead, both in terms of lost space on the host file system and in terms loading time for the emulator. As a *.T64 file contains a magic header it is furthermore possible for the emulator to prevent invalid files from being used.
  327.  
  328. typedef struct
  329.  {
  330.   TapeHeader Header;          /*  $0000  -  $003F  */
  331.   TapeEntry  Entry[MaxFiles]; /*  $0040  - ($03FF) */
  332.   Byte       Data[n];         /* ($0400) -   ...   */
  333.  } T64File;
  334.  
  335. Header - General information; containing a magic string to identify a *.T64 file, the number of files on the tape etc... (see below for details)
  336. Entry  - Tape Directory; A list of all files stored on the tape. The value MaxFiles is defined in Header, but is usually 30. (see below for details)
  337. Data   - The actual data for all the files.
  338.  
  339. typedef struct
  340.  {
  341.   Byte TapeDescr[32]; /* $00 - $1F */
  342.   Byte Version[2];    /* $20 - $21 */
  343.   Byte MaxFiles[2];   /* $22 - $23 */
  344.   Byte CurrFiles[2];  /* $24 - $25 */
  345.   Byte Reserved[2];   /* $26 - $27 */
  346.   Byte UserDescr[24]; /* $28 - $3F */
  347.  } TapeHeader;
  348.  
  349. TapeDescr - Magic string: "C64 tape image file"; padded with $00
  350.             Note this magic string need not be verbatim. Search for
  351.             substrings "C64" and "tape" to identify a *.T64 file.
  352. Version   - Tape Version 1.0 = {$00, $01}
  353. MaxFiles  - Number of places in the tape directory. There are some
  354.             some emulators that rely on fact that there are exactly
  355.             30 places in the directory. Thus all *.T64 files created
  356.             by Power64 will supply this value. = {$1E, $00}
  357. CurrFiles - Number of Files currently stored on the tape. This number
  358.             can never exceed MaxFiles. Note that some emulators can only
  359.             read the first file stored in a *.T64 image.
  360. Reserved  - Must be $00.
  361. UsedDescr - User Description of the Tape. (CBM character set)
  362.  
  363. typedef struct
  364.  {
  365.   Byte EntryUsed;     /* $00 */
  366.   Byte FileType;      /* $01 */
  367.   Byte StartAddr[2];  /* $02 - $03 */
  368.   Byte EndAddr[2];    /* $04 - $05 */
  369.   Byte ReservedA[2];  /* $06 - $07 */
  370.   Byte TapePos[4];    /* $08 - $0B */
  371.   Byte ReservedB[4];  /* $0C - $0F */
  372.   Byte FileName[16];  /* $10 - $1F */
  373.  } TapeEntry;
  374.  
  375. EntryUsed - Is this entry in the *.T64 directory used? (0..No, 1..Yes)
  376. FileType  - There is very little documentation on this field.
  377.             Power64 adopts the notion of Star Commander that corresponds
  378.             to the file type identifiers used on floppy disk:
  379.             $82..Relocateable Prg, $81..Data File
  380.             Earlier versions of Power64 implemented the following meaning:
  381.             0..Relocateable Prg., 1..Force Load Prg., 2..Data File
  382.             To prevent error messages all other values are also treated
  383.             a relocateable programs.
  384. StartAddr - Start of the destination range in C64 memory. (Low/High)
  385. EndAddr   - End of the destination range in C64 memory. (Low/High)
  386. ReservedA - Must be $00
  387. TapePos   - Offset from the start of the tape file to the logical
  388.             files data
  389. ReservedB - Must be $00
  390. FileName  - filename (CBM character set)
  391.  
  392. There was very little official documentation on the *.T64 file format. What is known was generally learned by examining existing *.T64 files. Sometimes that was not done with sufficient scrutiny. Thus there are many *.T64 files on the internet that do not follow the described format. It is, for example quite common, that the difference between EndAddr and StartAddr of a file is not consistent with the file size of the *.T64 file. Power64 attempts to automatically fix such inconsistencies.
  393.  
  394. As stated above there are some emulators that rely on the fact that there are always exactly 30 directory entries, while at the same time they will always load the first file. Please keep this in mind when making Commodore 64 files available to a general public that might use a wide range of emulators.
  395.  
  396. All multi-byte values are stored in the Little-Endian Format (Low/High) that is generally used by the C64.
  397.  
  398.  
  399. C.8 RAM Snapshot File
  400.  
  401. The format for RAM Snapshots was adapted from a suggestion made by Jouko Valta for the Vice-Emulator on Unix systems. The original description, that explains the meaning of the individual header fields in more detail, can be found at: http://stekt.oulu.fi:/~jopi/x64/RAM-format
  402.  
  403. typedef struct
  404.  {
  405.   Byte MagicCode[6];     /* $00 - $05 */
  406.   Byte ReservedA[2];     /* $06 - $07 */
  407.   Byte Version[2];       /* $08 - $09 */
  408.   Byte EmulatorID;       /* $0A */
  409.   Byte SnapType;         /* $0B */
  410.   Byte RAMStart[2];      /* $0C - $0D */
  411.   Byte RAMSizeKB[2];     /* $0E - $0F */
  412.   Byte REUSizeKB[2];     /* $10 - $11 */
  413.   Byte ReservedB[14];    /* $12 - $1F */
  414.   Byte Config[6];        /* $20 - $25 */
  415.   Byte IORAM;            /* $26 */
  416.   Byte CPURestore;       /* $27 */
  417.   Byte PCHigh, PCLow;    /* $28 - $29 */
  418.   Byte RegA, RegX, RegY; /* $2A - 2C */
  419.   Byte RegFlags, RegSP;  /* $2D - $2E */
  420.   Byte IOPort;           /* $2F */
  421.   Byte Z80_CPU[16];      /* $30 - $3F */
  422.   Byte REC[16];          /* $40 - $4F */
  423.   Byte OSVersion;        /* $50 */
  424.   Byte OSPatch;          /* $51 */
  425.   Byte PatchID[2];       /* $52 - $53 */
  426.   Byte ReservedC[44];    /* $54 - $7F */
  427.   Byte Custom[128];      /* $80 - $FF */
  428.   Byte RAM[65536];
  429.   Byte IOArea[4096];
  430.   Byte REU[REUSize];
  431.   FloppyState Floppy1541[FloppyCnt];
  432.  } Snapshot;
  433.  
  434. Note: All multi-byte values are stored in Big-Endian Format (High/Low) rather than in the Little-Endian Format (Low/High) used by the C64.
  435.  
  436. MagicCode  - Magic Constant 'CBM'64 = {$43, $42, $4D, $64, $00, $00}
  437. ReservedA   - Should be {$00, $00}
  438. Version        - Major and Minor Version Number 1.0 = {$01, $00}
  439. EmulatorID  - Power64 uses '/' = $2F
  440. SnapType    - RAM Snapshot = $00
  441. RAMStart    - Offset to the RAM Image in the File. The header currently uses 256 Bytes. Thus RAMStart = {$01, $00}.
  442. RAMSizeKB - Size of the RAM Image in KByte (not Byte!) = {$00, $40}
  443. REUSizeKB - Size of the RAM Expansion Unit in KByte
  444. ReservedB   - Should be all $00
  445. Config         - Reserved for configuration bit masks - Currently all $00
  446. IORAM       - Bit 2/1: VDC RAM available (00..No,   01..16KB, 10..64KB, 11..32KB)
  447.                       Bit 0:   I/O data available (0..No, 1..Yes)
  448.                       Value used by Power64: $01
  449. CPURestore - CPU(s) available: (Bit 0: M6502, Bit 1: Z80, Bit 2: REC) = $01
  450. PCHigh, PCLow - M6502 Program Counter
  451. RegA, RegX, RegY, RegFlags, RegSP - M6502 Registers
  452. IOPort          - 6502 CPU I/O latch
  453. Z80_CPU    - Reserved for internal state of Z80 (not used)
  454. REC            - Reserved for internal state of REC (not used)
  455. OSVersion  - C64 Kernal ID byte (not used)
  456. OSPatch      - Kernal patch ID for extensions (fastloaders etc.) (not used)
  457. PatchID       - Patch version information  (not used)
  458. ReservedC  - Kernal version information (not used)
  459. Custom       - Information on peripherals, external devices etc. (not used)
  460. RAM           - Contents of the RAM
  461. IOArea        - Contents of the I/O-Area (VIC, SID, ColorRAM, CIA1/2, REU)
  462.              Every device is stored only once, even so several shadows appear in the C64 address space. The gaps are filled with Power64 internal state information and lots of $00.
  463. REU            - The Contents of the REU RAM, if a RAM Expansion is present.
  464.                       0, 128, 256 or 512 KByte - as specified by REUSizeKB.
  465. Floppy1541 - The current state of each attached, completly emulated Floppy 1541.
  466.      typedef struct
  467.    {
  468.     Byte MagicCode[6];     /* $00 - $05 ('CBM',$15, $41, $00) */
  469.     Byte ReservedA[2];     /* $06 - $07 */
  470.     Byte Version[2];       /* $08 - $09 */
  471.     Byte EmulatorID;       /* $0A */
  472.     Byte SnapType;         /* $0B */
  473.     Byte RAMStart[2];      /* $0C - $0D */
  474.     Byte RAMSizeKB[2];     /* $0E - $0F */
  475.     Byte REUSizeKB[2];     /* $10 - $11 */
  476.     Byte ReservedB[14];    /* $12 - $1F */
  477.     Byte Config[6];        /* $20 - $25 */
  478.     Byte IORAM;            /* $26 */
  479.     Byte CPURestore;       /* $27 */
  480.     Byte PCHigh, PCLow;    /* $28 - $29 */
  481.     Byte RegA, RegX, RegY; /* $2A - 2C */
  482.     Byte RegFlags, RegSP;  /* $2D - $2E */
  483.     Byte ReservedC[81];    /* $2F - $7F */
  484.     Byte Custom[128];      /* $80 - $FF */
  485.     Byte RAM[2048];
  486.     Byte IOArea[512];
  487.  } FloppyState;
  488.